package com.hivekion.system.controller;

import com.hivekion.common.annotation.AutoLog;
import com.hivekion.common.core.SystemConstant;
import com.hivekion.common.enums.OperationTypeEnum;
import com.hivekion.common.redis.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/system/redis")
public class SysRedisController {

      @Autowired
      RedisUtil redisUtil;

      @GetMapping("getAllKey")
      public List<String> getAllKey() {
	    return redisUtil.keys("redis:menu:data").stream().collect(Collectors.toList());
      }

      @PostMapping("cleanKey")
      @PreAuthorize("@Permission.hasPermi('pro:sys:redis:clean')")
      public boolean cleanKey(String key) {
	    redisUtil.delete(key);
	    return true;
      }

      @PostMapping("clean")
      @PreAuthorize("@Permission.hasPermi('pro:sys:redis:clean')")
      @AutoLog(value = "清空缓存", operationType = OperationTypeEnum.CLEAN, module = "系统管理/Redis管理")
      public boolean cleanAllKey() {
	    redisUtil.delete(SystemConstant.redis_menu_data);
	    redisUtil.delete(SystemConstant.redis_dept_data);
	    redisUtil.delete(SystemConstant.redis_user_data);
	    redisUtil.delete(SystemConstant.redis_dict_data);
	    redisUtil.delete(SystemConstant.redis_area_data);
	    redisUtil.delete(SystemConstant.redis_item_data);
	    redisUtil.delete(SystemConstant.redis_target_data);
	    redisUtil.delete(SystemConstant.redis_target_sum_data);
	    redisUtil.delete(SystemConstant.redis_target_classic_data);
	    redisUtil.delete(SystemConstant.redis_biname_data);
	    redisUtil.delete(SystemConstant.redis_target_schame_data);
	    redisUtil.delete(SystemConstant.redis_item_schame_data);
	    redisUtil.delete(SystemConstant.redis_home_data);
	    redisUtil.delete(SystemConstant.redis_home_name_data);
	    redisUtil.delete(SystemConstant.redis_bi_data_data);
	    redisUtil.delete(SystemConstant.redis_score_data);
	    redisUtil.delete(SystemConstant.redis_score_record_data);

	    return true;
      }
}
